<?php

class Edit_Frontend {

    function getJSON(stdClass $request) {
        if (!isset($request->id))
            throw new Exception("request->id is required",1,null);
        if (!isset($request->attr))
            throw new Exception("request->attr is required",1,null);
        if (!isset($request->values))
            throw new Exception("request->values is required",1,null);

        $s = new Ldap_Backend();
        $s->open("localhost", "cn=Manager,dc=serpro,dc=gov,dc=br", "password");
        $query = $s->update($request->id)
                ->set(array($request->attr=>$request->values))
                ->exec();

        $cursor = $s->select($request->attr)
                ->from($request->id)
                ->exec();

        $response = array();
        while (($data = $cursor->fetch()))
            array_push($response, $data);

        return $response;
    }

}

?>
